package com.yj.daily.stream;

import java.util.ArrayList;

public class Demo02 {
    public static void main(String[] args) {
        ArrayList<UserTest> list = new ArrayList<>();

        list.add(new UserTest("liubei","111",40));
        list.add(new UserTest("zhangfei","222",30));
        list.add(new UserTest("guanyu","333",35));

        System.out.println("list: "+list.toString());

        System.out.println("\ntest1:");
        list.stream().map(n->n)
                .forEach(n-> System.out.println(n));

        System.out.println("\ntest2--age:");
        list.stream().map(n->n.getAge())
                .forEach(n-> System.out.println(n));

        System.out.println("\ntest3--age:");
        list.stream().map(n->n.getAge())
                .map(n->n).forEach(n-> System.out.println(n));

        System.out.println("\ntest2--username:");
        list.stream().map(n->n.getUsername())
                .forEach(n-> System.out.println(n));

        System.out.println("\ntest3--username:");
        //list.stream().map(n->n.getUsername()).map(n->n).forEach(n-> System.out.println(n));
        list.stream().map(n->n.getUsername())
                .forEach(n-> System.out.println(n));
    }
}
class UserTest{

    private String username;
    private String address;
    private int age;

    public UserTest(){

    }
    public UserTest(String username,String address,int age){
        this.username = username;
        this.address = address;
        this.age = age;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}